package demoMod.nanaki.cards.tempCards;

import basemod.ReflectionHacks;
import basemod.abstracts.CustomCard;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.evacipated.cardcrawl.modthespire.lib.SpireOverride;
import com.evacipated.cardcrawl.modthespire.lib.SpireSuper;
import com.megacrit.cardcrawl.actions.common.ExhaustSpecificCardAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.helpers.FontHelper;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import demoMod.nanaki.NanakiMod;
import demoMod.nanaki.cards.nanaki.AbstractNanakiCard;
import demoMod.nanaki.patches.AbstractCardEnum;

public abstract class AbstractBlessingCard extends CustomCard {
    public static final CardStrings cardStrings = CardCrawlGame.languagePack.getCardStrings(NanakiMod.makeID("AbstractBlessingCard"));

    public static ShaderProgram negativeShader;

    public AbstractBlessingCard(String id, String name, String img, String rawDescription) {
        super(id, name, img, -2, rawDescription, CardType.SKILL, AbstractCardEnum.BLESSING, CardRarity.SPECIAL, CardTarget.NONE);
        ReflectionHacks.setPrivate(this, AbstractCard.class,"textColor", AbstractNanakiCard.textColor.cpy());
        if (negativeShader == null) {
            negativeShader = new ShaderProgram(
                    Gdx.files.internal("NanakiShaders/negative/vertexShader.vsh"),
                    Gdx.files.internal("NanakiShaders/negative/fragShader.fsh")
            );
            if (!negativeShader.isCompiled()) {
                throw new RuntimeException(negativeShader.getLog());
            }
        }
    }

    @Override
    public boolean canUse(AbstractPlayer p, AbstractMonster m) {
        return false;
    }

    @Override
    public boolean canUpgrade() {
        return false;
    }

    @Override
    public void upgrade() {
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {
    }

    protected abstract void drawnEffect();

    @Override
    public void triggerWhenDrawn() {
        drawnEffect();
        addToTop(new ExhaustSpecificCardAction(this, AbstractDungeon.player.hand));
    }

    @SpireOverride
    public void renderCardBg(SpriteBatch sb, float x, float y) {
        ShaderProgram tmp = sb.getShader();
        sb.setShader(negativeShader);
        SpireSuper.call(sb, x, y);
        sb.setShader(tmp);
    }

    @SpireOverride
    protected void renderType(SpriteBatch sb) {
        BitmapFont font = FontHelper.cardTypeFont;
        font.getData().setScale(this.drawScale);
        FontHelper.renderRotatedText(sb, font, cardStrings.EXTENDED_DESCRIPTION[0], this.current_x, this.current_y - 22.0F * this.drawScale * Settings.scale, 0.0F, -1.0F * this.drawScale * Settings.scale, this.angle, false, Color.DARK_GRAY);
    }
}
